// import { _decorator, Component, Node, instantiate, Label, CCInteger, director } from 'cc';
import { MergeRoot } from './MergeRoot';
const { ccclass, property } = cc._decorator;


@ccclass('Main')
export class Main extends cc.Component {

    @property(cc.Node)
    contentNode: cc.Node = null;

    @property(cc.Node)
    itemNode: cc.Node = null;

    @property(cc.Label)
    stateLabel: cc.Label = null;

    @property(cc.Label)
    countLabel: cc.Label = null;

    @property(cc.Integer)
    maxItemCount: number = 0;

    start() {
        const max = this.maxItemCount;
        for (let index = 0; index < max; index++) {
            const n = cc.instantiate(this.itemNode) as cc.Node;
            n.active = true;
            this.contentNode.addChild(n);
        }

        // this.onSwitch();
        this.refreshStateLabel();

        this.countLabel.string = max.toString();
    }

    update(deltaTime: number) {

    }

    onSwitch() {

        MergeRoot.bMergeItem = !MergeRoot.bMergeItem;

        this.refreshStateLabel();
    }

    refreshStateLabel() {
        this.stateLabel.string = MergeRoot.bMergeItem ? "开启状态" : "关闭状态"
    }

    onSwitchScene() {
        const director = cc.director;
        const curScene = director.getScene().name;
        if (curScene == "main") {
            director.loadScene("main_ii");
            return;
        }
        director.loadScene("main");
    }
}


